package com.qdu.study_app.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.qdu.study_app.R;
import com.qdu.study_app.bean.comment;

import java.util.ArrayList;
import java.util.List;

public class CommentListAdapter extends BaseAdapter {


    private List<comment> commentList = new ArrayList<>();
    private Context context;

    public CommentListAdapter(Context context) {
        this.context = context;
    }

    public Context getContext() {
        return context;
    }

    @Override
    public int getCount() {
        return commentList.size();
    }

    @Override
    public Object getItem(int position) {
        return commentList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    /*
    * 获取List中的item，进行绘制
    * */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ListCell comment_list = new ListCell();
        if(convertView == null){
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.comment_list_cell,null);

            comment_list.setComment_uid(convertView.findViewById(R.id.comment_uid));
            comment_list.setComment_content(convertView.findViewById(R.id.comment_content));
        }
        comment_list.getComment_uid().setText(commentList.get(position).getFrom_uid());
        comment_list.getComment_content().setText(commentList.get(position).getContent());
        // 回复按钮未设置

        return convertView;
    }

    public void addAll(List<comment> data){
        commentList.addAll(data);
        notifyDataSetChanged();
    }

    public void clear(){
        commentList.clear();
        notifyDataSetChanged();
    }

    public static class ListCell{
        private TextView comment_uid;
        private TextView comment_content;
        private Button comment_to_btn;

        public ListCell() {
        }

        public TextView getComment_uid() {
            return comment_uid;
        }

        public void setComment_uid(TextView comment_uid) {
            this.comment_uid = comment_uid;
        }

        public TextView getComment_content() {
            return comment_content;
        }

        public void setComment_content(TextView comment_content) {
            this.comment_content = comment_content;
        }

        public Button getComment_to_btn() {
            return comment_to_btn;
        }

        public void setComment_to_btn(Button comment_to_btn) {
            this.comment_to_btn = comment_to_btn;
        }
    }
}
